package com.codetci.kafka;

import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author: zhenzhong.wang
 * @Time: 2018/08/21 23:01
 */
@RestController
public class KafkaTestController {

  @Autowired
  private KafkaTemplate<String, String> template;

  @GetMapping("/kafka/testOne")
  public void testOne() throws InterruptedException {
    ListenableFuture<SendResult<String, String>> send = template.send(new ProducerRecord<String, String>("1", "2"));
    this.template.send("test", "foo1");
    this.template.send("test", "foo2");
    this.template.send("test", "foo3");
    Thread.sleep(1000);
    System.out.println("All received");
  }
}
